package com.cn.springcloudwechat.controller.find.askDoctor;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.Const;
import com.cn.springcloudwechat.model.YmAnswer;
import com.cn.springcloudwechat.model.find.communication.YmAnswerVO;
import com.cn.springcloudwechat.service.YmAnswerService;
import com.cn.springcloudwechat.service.find.askDoctor.AskDoctorService;
import com.cn.springcloudwechat.service.find.communication.CommunicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("web/Answer/")
public class AnswerContrller {
    @Autowired
    CommunicationService communicationService;
    @Autowired
    YmAnswerService ymAnswerService;
    @Autowired
    AskDoctorService askDoctorService;
    /**
     * 问医生-快速提问
     * @param ymAnswer, douctorConsultTypeId
     * @return
     */
    @RequestMapping("insertYmAnswer")
    public AjaxRes insertYmAnswer(AjaxRes ajaxRes, YmAnswer ymAnswer,Long doctorId){
        try{
            String[] relevanceIdAndrelevanceTpyeId = ymAnswerService.insertYmAnswer(ymAnswer,doctorId);
            ajaxRes.setSucceed(relevanceIdAndrelevanceTpyeId, Const.OPERATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }

    /**
     * 问医生-提问回复
     * @param ymAnswer
     * @return
     */
    @RequestMapping("insertYmAnswerReply")
    public AjaxRes insertYmAnswerReply(AjaxRes ajaxRes, YmAnswer ymAnswer){
        try{
            String[] relevanceIdAndrelevanceTpyeId = ymAnswerService.insertYmAnswerReply(ymAnswer);
            ajaxRes.setSucceed(relevanceIdAndrelevanceTpyeId, Const.OPERATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }

    /**
     * 问医生- 删除提问
     * @param answerId
     * @return
     */
    @RequestMapping("deleteYmAnswer")
    public AjaxRes deleteYmAnswer(AjaxRes ajaxRes, Long answerId){
        try{
           Integer number = ymAnswerService.deleteYmAnswer(answerId);
            ajaxRes.setSucceed(number, Const.OPERATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }

    /**
     * 问医生-根据answerUserId和type查询属于当前用户的所有历史提问
     * @param type
     * @return
     */
    @RequestMapping("queryYmAnswerListAnswerByUserId")
    public AjaxRes queryYmAnswerListAnswerByUserId(AjaxRes ajaxRes, Integer type){
        try{

            List<Map<String,Object>> ymAnswerList = ymAnswerService.queryYmAnswersByAnswerUserId(type);
           ajaxRes.setSucceed(ymAnswerList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }
    /**
     * 问医生-根据answerUserId和type查询属于当前用户的所有历史提问以及回复
     * @param answerUserId
     * @return
     */
    @RequestMapping("queryYmAnswerDetailByAnswerUserId")
    public AjaxRes queryYmAnswerDetailByAnswerUserId(AjaxRes ajaxRes, Long typeId, Long answerUserId, Integer type){
        try{
        	
            List<Map<String,Object>> ymAnswerList = ymAnswerService.queryYmAnswerDetailByAnswerUserId(typeId,answerUserId,type);
            ajaxRes.setSucceed(ymAnswerList,Const.DATA_SUCCEED);
            System.out.print(ymAnswerList);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }
    /**
     * 问医生-根据医生ID(typeId)以及提问类型(type)查询属于当前医生的所有提问
     * @param typeId, type
     * @return
     */
    @RequestMapping("queryYmAnswerList")
    public AjaxRes queryYmAnswerList(AjaxRes ajaxRes, Long typeId, Integer type, String praiseType){
        try{
            List<YmAnswerVO> ymAnswerVOList = ymAnswerService.queryYmAnswerListByTypeId(typeId, type, praiseType);
            ajaxRes.setSucceed(ymAnswerVOList, Const.OPERATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }

    /**
     * 问医生-根据typeId和answerUserId查询提问回复明细
     * @param typeId, answerUserId
     * @return
     */
    @RequestMapping("queryYmAnswerListDetail")
    public AjaxRes queryYmAnswerListDetail(AjaxRes ajaxRes, Long typeId, Long answerId, String praiseType){
        try{
            Map<String,Object> map = ymAnswerService.queryYmAnswerListDetail(typeId,answerId,praiseType );
            ajaxRes.setSucceed(map, Const.OPERATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return  ajaxRes;
    }
}
